﻿using System;
using System.Windows.Forms;
using ApplicationGenerator.BusinessModule.MetaElements;
using ApplicationGenerator.Forms.WebControls;

namespace FormsTests
{
    public partial class Form1 : Form
    {
        public Form1()
        {

            InitializeComponent();

            InitializeTests();

            AddBaseControl();
        }

        private ButtonControl _control;

        private void AddBaseControl()
        {
            _control = new ButtonControl();
            //_control.Source = (new FacadeFactory()).CreateMetaModelFacade().MetaAdapterCollection["Movie"];


            BaseControl baseControl = _control;
            this.propertyGrid1.SelectedObject = baseControl;
        }

        private void InitializeTests()
        {
            MetaModelManager metaManager = MetaModelManager.Instance;
            string path = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\") + 1);
            string pathToAssembly = System.IO.Path.Combine(path, "BusinessModels.dll");
            string pathToXmlFile = System.IO.Path.Combine(path, "ActiveRecordTestConfig.xml");
            System.Reflection.Assembly modelsAssembly = System.Reflection.Assembly.LoadFile(pathToAssembly);
            System.Reflection.AssemblyName assemblyName = modelsAssembly.GetName();
            System.Reflection.Assembly assembly = AppDomain.CurrentDomain.Load(assemblyName);
            Castle.ActiveRecord.ActiveRecordStarter.Initialize(assembly, new Castle.ActiveRecord.Framework.Config.XmlConfigurationSource(pathToXmlFile));
            //ActiveRecordStarter.CreateSchema();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //_control.Validate(new StringBuilder());
        }
    }
}
